#! /bin/bash
#SQOOP_HOME=/opt/cloudera/parcels/CDH-6.2.1-1.cdh6.2.1.p0.1425774/bin/sqoop
SQOOP_HOME=/usr/bin/sqoop
if [[ $1 == "" ]];then
   TD_DATE=`date -d '1 days ago' "+%Y-%m-%d"`
else
   TD_DATE=$1
fi

echo '========================================'
echo '==============开始全量导入==============='
echo '========================================'

# 访问与咨询信息主表
/usr/bin/sqoop import "-Dorg.apache.sqoop.splitter.allow_text_splitter=true" \
--connect 'jdbc:mysql://106.75.33.59:3306/nev?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true' \
--username itcast_edu_stu \
--password itcast_edu_stu \
--query "select *, '2022-10-13' as dt from web_chat_ems_2019_07 where 1=1 and  \$CONDITIONS" \
--hcatalog-database zx_ods \
--hcatalog-table t_web_chat_ems \
-m 1
wait

# 访问与咨询信息副表
/usr/bin/sqoop import "-Dorg.apache.sqoop.splitter.allow_text_splitter=true" \
--connect 'jdbc:mysql://106.75.33.59:3306/nev?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true' \
--username itcast_edu_stu \
--password itcast_edu_stu \
--query "select *,'2021-10-13' as dt from web_chat_text_ems_2019_07 where 1=1 and  \$CONDITIONS" \
--hcatalog-database zx_ods \
--hcatalog-table t_web_chat_text_ems \
-m 1
wait



# 访问与咨询信息主表(增量脚本)
/usr/bin/sqoop import "-Dorg.apache.sqoop.splitter.allow_text_splitter=true" \
--connect 'jdbc:mysql://192.168.88.80:3306/nev?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true' \
--username itcast_edu_stu \
--password itcast_edu_stu \
--query "select *, '${TD_DATE}' as dt from web_chat_ems_2019_07 where 1=1 and login_time between 
'${TD_DATE} 00:00:00' and '${TD_DATE} 23:59:59' and  \$CONDITIONS" \
--hcatalog-database zx_ods \
--hcatalog-table t_web_chat_ems \


# 访问与咨询信息副表(增量表)

/usr/bin/sqoop import "-Dorg.apache.sqoop.splitter.allow_text_splitter=true" \
--connect 'jdbc:mysql://192.168.88.80:3306/nev?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true' \
--username itcast_edu_stu \
--password itcast_edu_stu \
--query "select *, '${TD_DATE}' as dt from web_chat_text_ems_2019_07 where 1=1 and login_time between 
'${TD_DATE} 00:00:00' and '${TD_DATE} 23:59:59' and  \$CONDITIONS" \
--hcatalog-database zx_ods \
--hcatalog-table t_web_chat_text_ems \

echo '========================================'
echo '=================success==============='
echo '========================================'